package com.material.controller.employee;

import com.material.common.annotation.LoginUser;
import com.material.common.core.domain.entity.SysUser;
import com.material.common.entity.ResultResponse;
import com.material.common.utils.DateUtils;
import com.material.common.utils.OcrUtil;
import com.material.common.utils.StringUtils;
import com.material.supplier.service.ISupplierReservationService;
import com.material.supplier.vo.SupplierReservationDataVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author ganxinge
 */
@Api(tags = "员工端车辆核验")
@RestController
@RequestMapping("/employee/car")
public class EmployeeCarCheckController {

    @Autowired
    private ISupplierReservationService supplierReservationService;

    @ApiOperation("ocr识别车牌")
    @GetMapping("/ocrCar")
    public ResultResponse<Object> ocrCar(String imageUrl){
        String s = OcrUtil.ocrCar(imageUrl);
        if(StringUtils.isBlank(s)){
            return ResultResponse.error("未能识别到车牌号");
        }
        Object rs = s;
        return ResultResponse.success(rs);
    }

    @ApiOperation("通过车牌查询预约记录")
    @GetMapping("/findReservation/{carNum}")
    public ResultResponse findReservation(@ApiIgnore @LoginUser SysUser sysUser,@PathVariable("carNum") String carNum){
        Long bizId = sysUser.getBizId();
        String currentDate = DateUtils.dateTime(DateUtils.getNowDate());
        SupplierReservationDataVo supplierReservationDataVo = supplierReservationService.selectSupplierReservationByCarNum(currentDate, carNum);
        if(supplierReservationDataVo == null){
            return ResultResponse.success();
        }
        return ResultResponse.success(supplierReservationDataVo);
    }

    @ApiOperation("确认签到")
    @GetMapping("/signUp/{id}")
    public ResultResponse signUp(@PathVariable("id") Long id){
        supplierReservationService.signUp(id);
        return ResultResponse.success();
    }
}
